import { MigrationInterface, QueryRunner } from 'typeorm'
import RequestLog from '@/models/mongo/RequestLog'

export class RequestLog1726116834390 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    const requestLogRepository = queryRunner.manager.getMongoRepository(RequestLog)
    requestLogRepository.createCollectionIndex('user_id', { sparse: true, name: 'user_id_index' })
    requestLogRepository.createCollectionIndex('request_at', { name: 'request_at_index' })
    requestLogRepository.createCollectionIndex('res_status', { name: 'res_status_index' })
    requestLogRepository.createCollectionIndex('has_error', { name: 'has_error_index' })
    requestLogRepository.createCollectionIndex('created_at', { name: 'created_at_index' })
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    const requestLogRepository = queryRunner.manager.getMongoRepository(RequestLog)
    requestLogRepository.dropCollectionIndex('user_id')
    requestLogRepository.dropCollectionIndex('request_at')
    requestLogRepository.dropCollectionIndex('created_at')
    requestLogRepository.dropCollectionIndex('res_status')
    requestLogRepository.dropCollectionIndex('has_error')
  }
}
